import { DbService } from '@app/db';
import { User } from '@app/db/entities/User';
import { Body, Controller, Get, Post, Req } from '@nestjs/common';
import { FindOptionsWhere } from 'typeorm';
import { BaseController } from '../base/base.controller';
import { PageDto } from './dto';

@Controller('user')
export class UserController  extends BaseController {
    constructor(
        private readonly db:DbService
    ){
        super()
    }

    @Get('page')
    async page(@Body() dto:PageDto, @Req() { locale }) {
       
        let result:PaginationResult<User> = {
            total : 0,
            rows : []
        }

        let where:FindOptionsWhere<User> = {
            
        }

        
        if(dto.nickname) {
            where.nickname = dto.nickname
        }

        result.total = await this.db.user.count(where)

        if(result.total > 0) {
            result.rows = await this.db.user.pagination(dto.pageNo, dto.pageSize, where, null, {id : 'DESC'})
        }
        

        return this.successRes(result)

    }
}

